package com.easyj.admin.sys.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.easyj.base.common.ajax.Result;
import com.easyj.base.controller.BaseController;
import com.easyj.admin.db.model.Permission;
import com.easyj.admin.sys.service.PermissionService;
	/**
	* 权限
	*
	 */
	@RestController
	@RequestMapping(value = "/sys/permission")
	@PreAuthorize("hasPermission('permission','permission:all')")
	public class PermissionController extends BaseController{

		@Autowired
		private  PermissionService permissionService;

		/**
		 * get
		 * @param id
		 * @return
		*/ 
	    @GetMapping("/{id}")
	    public Result get(@PathVariable("id") Long id) {
	        Permission entity = permissionService.findById(id);
	        return Result.Success(entity);
	    }
	    
		
		/**
		* 查询
		* @param filter
		* @return
		 */
		@RequestMapping(value = "getTree", method = {RequestMethod.GET,RequestMethod.POST})
		public Result getTree() {
			return Result.Success(permissionService.getTree());	
		}
		
		/**
		* 停用
		* @param ids
		* @return
		*/
		@RequestMapping(value = "disable", method = RequestMethod.POST)
		public Result disable(@RequestParam(value = "id") Long id){
			permissionService.disableById(id);
			return Result.Success();  
		}
		
		/**
		 * 启用
		* @param id
		* @return
		*/
		@RequestMapping(value = "enable", method = RequestMethod.POST)
		public Result enable(@RequestParam(value = "id") Long id){
			permissionService.enableById(id);
			return Result.Success();
           			
		}
}

